#ifndef __WEBPAGE_H__
#define __WEBPAGE_H__

#include <string>
#include <vector>
#include <map>
#include <unordered_set>
#include <algorithm>

struct RssItem;
class WordSegmentation;

using std::string;
using std::vector;
using std::map;
using std::unordered_set;


class WebPage
{
public:
    WebPage();
    WebPage(const RssItem &rss);
    WebPage(const string &doc);
    
    size_t getDocId() const { return _docId; }
    string getDocTitle() const { return _docTitle; }
    string getDocLink() const { return _docUrl; }
    string getDocContent() const { return _docContent; }
    string getDocSummary() const { return _docSummary; }
    string &getDoc() { return _doc; }  
    size_t getLength() const { return _length; }
    int getTotalWordsFreq () { return _totalWordsFreq; }


    void setDocId(size_t docId) { _docId = docId; }
    void makeformatDoc() {
        _docContent.erase(remove_if(_docContent.begin(),_docContent.end(),::isspace),_docContent.end());
        _docContent.erase(remove(_docContent.begin(),_docContent.end(),'\n'),_docContent.end());
        _docContent.erase(remove(_docContent.begin(),_docContent.end(),'\t'),_docContent.end());
        _doc = "<doc>\n\t<docid>" + std::to_string(_docId) + "</docid>\n" +
                "\t<title>" + _docTitle + "</title>\n" + 
                "\t<url>" + _docUrl + "</url>\n" +
                "\t<content>" + _docContent + "</content>\n" + "</doc>\n";
        _length = _doc.size();
    }

    map<string, int> & getWordsFreq() { return _wordsFreq; }
    void createWordsFreq(const unordered_set<string>& stopWords, WordSegmentation &wordSeg);
    void dealWord(string& word);
    void processDoc();

private:
    string _doc; 
    size_t _docId;
    string _docTitle;
    string _docUrl;
    string _docContent;
    string _docSummary;
    size_t _length;
    int _totalWordsFreq;

    map<string, int> _wordsFreq;
};

#endif